namespace StreetCrime
{
    using System;
    using Serialization;
    using WP7Contrib.Common;

    [Serializer(typeof(StreetLevelCrimeCriteria))]
    public sealed class StreetLevelCrimeCriteria : BaseModel, ISerializeObject, IEquatable<StreetLevelCrimeCriteria>
    {
        private double latitude;

        private double longitude;

        public StreetLevelCrimeCriteria()
        {
        }

        public object[] Serialize(object target)
        {
            var criteria = (StreetLevelCrimeCriteria)target;
            return new object[] { criteria.Latitude,
                                  criteria.Longitude };
        }

        public object Deserialize(object[] data)
        {
            var criteria = new StreetLevelCrimeCriteria
            {
                Latitude = (double)data[0],
                Longitude = (double)data[1]
            };

            return criteria;
        }

        public double Latitude
        {
            get
            {
                return this.latitude;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.latitude, value, () => this.Latitude);
            }
        }

        public double Longitude
        {
            get
            {
                return this.longitude;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.longitude, value, () => this.Longitude);
            }
        }

        public static bool operator ==(StreetLevelCrimeCriteria slcc1, StreetLevelCrimeCriteria slcc2)
        {
            return Equals(slcc1, slcc2);
        }

        public static bool operator !=(StreetLevelCrimeCriteria slcc1, StreetLevelCrimeCriteria slcc2)
        {
            return !Equals(slcc1, slcc2);
        }

        public bool Equals(StreetLevelCrimeCriteria criteria)
        {
            if (ReferenceEquals(null, criteria))
            {
                return false;
            }

            if (this.Latitude != criteria.Latitude)
            {
                return false;
            }

            if (this.Longitude != criteria.Longitude)
            {
                return false;
            }

            return true;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            return obj is StreetLevelCrimeCriteria && this.Equals((StreetLevelCrimeCriteria)obj);
        }

        public override int GetHashCode()
        {
            return this.CombineHashCodes(this.Latitude, this.Longitude);
        }
    }
}